package com.spring.springboot;

import com.spring.springboot.circulardependency.dto.A;
import com.spring.springboot.config.MyApplicationContextAware;
import com.spring.springboot.config.MyBeanNameAware;
import com.spring.springboot.config.TestBean;
import com.spring.springboot.dto.Student;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author xiaohuihui
 */
@SpringBootApplication
public class SpringbootApplication {

    public static void main(String[] args) {
//        ApplicationContext applicationContext=new AnnotationConfigApplicationContext("com.spring.springboot");

//        Map<String, Student> beansOfType = applicationContext.getBeansOfType(Student.class);

        //测试MyStudentFactoryBean
//        Object student = applicationContext.getBean("myStudentFactoryBean");
//        System.out.println(student);
//        Object student1 = applicationContext.getBean("&myStudentFactoryBean");
//        System.out.println(student1);

//        Object student = applicationContext.getBean(Student.class);
//        System.out.println(student);
        System.setProperty("spring.main.allow-circular-references", "true");
        SpringApplication.run(SpringbootApplication.class, args);

        //测试MyBeanFactoryPostProcessor
//        Object testBean = applicationContext.getBean(TestBean.class);
//        Object testBean1 = applicationContext.getBean(TestBean.class);
//        System.out.println(testBean);
//        System.out.println(testBean1);

        //测试MyBeanNameAware
//        MyBeanNameAware bean = applicationContext.getBean(MyBeanNameAware.class);
//        String beanName = bean.getBeanName();
//        System.out.println(beanName);

        //测试MyApplicationContextAware
//        Object bean = MyApplicationContextAware.getBean(TestBean.class);
//        System.out.println(bean);

//        A bean = applicationContext.getBean(A.class);
//        System.out.println(bean);
    }

}
